package com.example.dinghao.recyclerviewtest312dh.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.dinghao.recyclerviewtest312dh.adapter.tcaseAdapter;
import com.example.dinghao.recyclerviewtest312dh.R;

import com.example.dinghao.recyclerviewtest312dh.bean.tcaseBean;
import com.example.dinghao.recyclerviewtest312dh.iface.tcaseListener;
import com.example.dinghao.recyclerviewtest312dh.model.tcaseModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private tcaseAdapter tcaseAdapter;
    private List<tcaseBean> list=null;
    tcaseListener tcaseListener =new tcaseListener() {
        @Override
        public void onResponse(List<tcaseBean> beanList) {
            list=beanList;
            tcaseAdapter.setList(list);
            tcaseAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecycleView();
        tcaseModel tcaseModel =new tcaseModel();
        tcaseModel.getResultList("tcase",2,"k17vmm42ui9al6clh0lo3de2t7", tcaseListener);



    }

    private void initRecycleView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        // list=getData();
        tcaseAdapter =new tcaseAdapter(this);
        tcaseAdapter.setList(list);
        recyclerView.setAdapter(tcaseAdapter);
    }



        
}
